//Unit test for Sea Hag

#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <assert.h>

void randCards(struct gameState* state);

void fail(int n) {
    printf("FAIL !!!\n");
    exit(n);
}

int main() {
	struct gameState state;
	int deckCount[4];
	int discardCount[4];
	int handCount[4];
	int totalPlayers = 4;
	int player = 0;
	int i, k, l, p;
	srand (time(NULL));
	
	randCards(&state);
	l = rand() % state.handCount[player];
	state.hand[player][l] = sea_hag;
	
	for(p = 0; p < totalPlayers; ++p) {
		handCount[p] = state.handCount[p];
		deckCount[p] = state.deckCount[p];
		discardCount[p] = state.discardCount[p];
	}
	state.playedCardCount = 0;
	
	k = cardEffect(sea_hag, 0, 0, 0, &state, l, NULL);
	if(k != 0) fail(0);
	for(p = 1; p < totalPlayers; ++p) {
		if(state.deckCount[p] != deckCount[p]) fail(0);
		if(state.deck[p][state.deckCount[p] - 1] != curse) fail(0);
	}

	if(state.playedCards[state.playedCardCount - 1] != sea_hag)
        fail(0);
	if(state.handCount[player] != (handCount[player] - 1)) fail(0);

	printf("Passed.\n");
	return 0;
}

void randCards(struct gameState* state) {
	int i, p;
	
	for(p = 0; p < 4; ++p) {
		state->handCount[p] = 5;
		for (i = 0; i < state->handCount[p]; ++i) {
			state->hand[p][i] = rand() % 27;
		}
		
		state->discardCount[p] = 10;
		for (i = 0; i < state->discardCount[p]; ++i) {
			state->discard[p][i] = rand() % 27;
		}
		
		state->deckCount[p] = 10;
		for (i = 0; i < state->deckCount[p]; ++i) {
			state->deck[p][i] = rand() % 27;
		}
	}
}
